package com.icangya.DAO.impl;

import com.icangya.DAO.IFbTurntableRecordDAO;
import com.icangya.domain.FbMissionRecord;
import com.icangya.domain.FbTurntableRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;


@Repository
public class FbTurntableRecordDAOImpl extends  BaseDAO<FbTurntableRecord> implements IFbTurntableRecordDAO {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public List<FbTurntableRecord> getFbTurntableRecord(long uid) {

        String hql="FROM FbTurntableRecord bm where bm.status=0 and bm.uid=?";
        return (List<FbTurntableRecord>) getHibernateTemplate().find(hql,uid);
    }

    @Override
    public Long getFbTurntableRecordCount(String openId) {
       String  hql="SELECT COUNT(bm) FROM FbTurntableRecord bm where bm.status=0 and bm.openId= '"+openId+"'";

        Long total = (Long) getHibernateTemplate().find(hql).get(0);
        return total;
    }

    @Override
    public FbTurntableRecord getTurntableRecordBySystem(long missionId,String openId) {

        String hql="FROM FbTurntableRecord mr where to_days(mr.createTime)= to_days(?) and mr.missionId=? and mr.openId =? ";
        List<FbTurntableRecord> list= (List<FbTurntableRecord>) getHibernateTemplate().find(hql,new Timestamp(new Date().getTime()),missionId,openId);
        if(list.size()>0)
            return list.get(0);
        return null;
    }
}
